#pragma once
#include "Camera.h"
#include <graphics.h>
#include "Vector2.h"
#pragma comment(lib,"MSIMG32.LIB")

inline void flip_image(IMAGE* src, IMAGE* dst)
{
	int width = src->getwidth();
	int height = src->getheight();

	Resize(dst, width, height);
	DWORD* src_Buffer = GetImageBuffer(src);
	DWORD* dst_Buffer = GetImageBuffer(dst);
	for (int y = 0; y < height; y++)
	{
		for (int x = 0; x < width; x++)
		{
			int src_index = y * width + x;
			int dst_index = y * width + (width - x - 1);
			dst_Buffer[dst_index] = src_Buffer[src_index];
		}
	}
}

inline void putimage_lapha(const Camera& camera,int dst_x, int dst_y, IMAGE* img)
{
	int width = img->getwidth();
	int height = img->getheight();

	AlphaBlend(GetImageHDC(GetWorkingImage()), dst_x, dst_y, width, height,
		GetImageHDC(img), 0, 0, width, height, {AC_SRC_OVER,0,255,AC_SRC_ALPHA});
}


inline void putimage_lapha(int dst_x, int dst_y, IMAGE* img)
{
	int width = img->getwidth();
	int height = img->getheight();

	AlphaBlend(GetImageHDC(GetWorkingImage()), dst_x, dst_y, width, height,
		GetImageHDC(img), 0, 0, width, height, { AC_SRC_OVER,0,255,AC_SRC_ALPHA });
}

inline void putimage_lapha(int dst_x, int dst_y ,int width,int height,IMAGE* img,int src_x,int src_y)
{
	int w = width > 0 ? width : img->getwidth();
	int h = height > 0 ? height : img->getheight();

	AlphaBlend(GetImageHDC(GetWorkingImage()), dst_x, dst_y, w, h,
		GetImageHDC(img), src_x, src_y, w, h, { AC_SRC_OVER,0,255,AC_SRC_ALPHA });
}

inline void line(const Camera& camera,int x1,int y1,int x2,int y2)
{
	const Vector2& pos_camra = camera.Get_position();
	line((int)(x1 - pos_camra.x), (int)(y1 - pos_camra.y), (int)(x2 - pos_camra.x), (int)(y2 - pos_camra.y));

}

inline void sketch_image(IMAGE* src,IMAGE* dst)
{
	int width = src->getwidth();
	int height = src->getheight();
	Resize(dst, width, height);
	DWORD* src_Buffer = GetImageBuffer(src);
	DWORD* dst_Buffer = GetImageBuffer(dst);

	for (int y =0;y< height;y++)
	{
		for (int x=0;x<width;x++)
		{
			int idx = y * width + x;
			dst_Buffer[idx] = BGR(RGB(255, 255, 255)) | (src_Buffer[idx] & 0xFF000000);
		}
	}
}